#ifndef ETHERCATTHREAD_H
#define ETHERCATTHREAD_H


#include <QThread>

#include "coeecatdevice.h"

///线程同步使用例子
//        pthread_mutex_lock(&pthreadMutex);
//        pthread_cond_wait(&cond,&pthreadMutex);
//        pthread_mutex_unlock(&pthreadMutex);

/**
 * @brief The mythread class  说明: ethercat 专属 xenomai 线程
 */
class  EthercatThread : public QThread
{
    Q_OBJECT
public:
    explicit EthercatThread(  int sleeptime , QObject *parent = 0);
    ~EthercatThread(){
        stop();
    }
    /**
   * @brief start 运行
   */
    void start(){
        isRun = true;
        QThread::start();
    }
    /**
   * @brief stop 停止
   */
    void stop(){
        isRun = false;
        isFinished();
        quit();
        if( !wait(100) ){
            qDebug()<<"ethercat thread quit failed！";
        }
    }

    ///ethercat 指针
    CoeEcatDevice *eCat ;
    ///while(run) 运行标志
    bool isRun;

    /// 时间间隔
    int timeInval;

protected:

    /**
   * @brief run 重载 run()
   */
    virtual void run();

signals:

public slots:

};

#endif // ETHERCATTHREAD_H
